const sleep = require('util').promisify(setTimeout)


async function MyAsyncFunc(time) {
  await sleep(time);
  return 2;
}


(async function(){
  let now = Date.now();
  const result = await Promise.all([MyAsyncFunc(1000), MyAsyncFunc(2000)]);
  let end = Date.now();
  console.log(result, end-now);
})()



const myAsyncFunction = (s) => {
  return new Promise((resolve) => {
      setTimeout(() => resolve(s), 2000);
  })
};

(async function() {
  const result = await Promise.race([
      myAsyncFunction(2),
      myAsyncFunction(3)
  ]);
  // outputs `2` after three seconds
  console.log(result);
})();



